/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tds;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;

/**
 *
 * @author cwhitela
 */
public class Tweet {

	String id;
	String username;
	String dateTime;
	String message;
	Collection<String> mentions;

	public Tweet() {
		id = null;
		username = null;
		dateTime = null;
		message = null;
		mentions = null;
	}

	public Tweet(UserTimelineResponse.Entry entry) {
		
		id = entry.id_str;
		username = entry.user.screen_name;
		dateTime = entry.created_at;
		message = entry.text.replace('\n', ' ').replace('\r', ' ');
		mentions = new ArrayList();
		
		if (entry.entities != null)
		{
			if (entry.entities.user_mentions != null)
			{
				for (UserTimelineResponse.Entry.Entities.User_mentions user : entry.entities.user_mentions)
				{
					if (user.screen_name != null)
						if (! mentions.contains(user.screen_name))
							mentions.add(user.screen_name);
				}
			}
		}
	}
	
	public static Collection<Tweet> massConstructor(Collection<SearchResponse.Result> c) {
		Collection<Tweet> tweets = new ArrayList<Tweet>();
		for (SearchResponse.Result r : c) {
			tweets.add(new Tweet(r));
		}
		
		return tweets;
	}
	
	public Tweet(SearchResponse.Result r) {
		this.id = r.getIt_str();
		this.username = r.getFrom_user();
		this.dateTime = r.getCreated_at();
		this.message = r.getText().replace('\n', ' ').replace('\r', ' ');
		this.mentions = null;
	}

	@Override
	public String toString() {
		return id + "\t" + username + "\t" + dateTime + "\t" + message;
	}
	
	public String toSimpleString()
	{
		MyDateFormatter mdf = new MyDateFormatter();
		
		String newDateTime = mdf.getFormattedDateTimeString(dateTime);
		return id + "\t" + username + "\t" + newDateTime + "\t" + message;
	}
}
